﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using snat.model;

namespace algorithms.utils.resultsets
{
    public class ResultMatrix<K>
    {
        public float[,] valuearray{
         get; private set;   
        }


        public List<K> Keys {
            get {
                return indexLookup.Keys.ToList();
            }
        }


        public Dictionary<K, int> indexLookup {
            get;
            private set;
        }

        public int Dimension {
            get {
                return indexLookup.Count;
            }
        }

        public float this[K a, K b]{
            get {
                return valuearray[indexLookup[a], indexLookup[b]];
            }
            set {
                valuearray[indexLookup[a], indexLookup[b]] = value;
            }
        }


        public ResultMatrix(float[,] _valuearray, Dictionary<K, int> _indexLookup) {
            valuearray = _valuearray;
            indexLookup = _indexLookup;
        }


        public List<K> AllReachingTo(K target) {
            List<K> reaching = new List<K>();
            foreach (K other in Keys) {
                if(!float.IsInfinity(this[other, target])){
                    reaching.Add(other);
                }
            }
            return reaching;
        }

        public List<K> AllReachableFrom(K source) {
            List<K> reachables = new List<K>();
            foreach (K other in Keys){
                if(!float.IsInfinity(this[source , other])){
                    reachables.Add(other);
                }
            }
            return reachables;
        }





    }
}
